package com.pro.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;

import com.pro.entity.BannerEntity;
import com.pro.entity.ProductTypeEntity;
import com.pro.util.DBManager;
import com.pro.util.QueryResult;

public class ProductTypeDaoImpl {
	public ArrayList<ProductTypeEntity> productType(){
		ArrayList<ProductTypeEntity> alist= new ArrayList<ProductTypeEntity>();
		String sqlString="select id,create_time,name from product_type";
	    QueryResult rSet=DBManager.executeQuery(sqlString);
	      if (rSet!=null) {
	        try {
	          while (rSet.rs.next()) {
	        	  alist.add(new ProductTypeEntity(rSet.rs.getInt("id"),
	            		rSet.rs.getString("create_time"),
	            		rSet.rs.getString("name")));
	          }
	        } catch (SQLException e) {
	          e.printStackTrace();
	        }
	      }
	      rSet.close();
	    return alist;
	}
	
	public int productTypeAdd(ProductTypeEntity pEntity) {
 		String sqlString="insert into product_type(name,create_time) values('"+pEntity.getName()+"','"+pEntity.getCreateTime()+"')";
 		 int result= DBManager.executeUpdate(sqlString);
 		return result;
 	}
	
	 public int productTypeUpdate(ProductTypeEntity pEntity) {
	 		String sqlString="update product_type set name='"+pEntity.getName()+"',create_time='"+pEntity.getCreateTime()+"' where id = '"+pEntity.getId()+"'";
	 		 int result= DBManager.executeUpdate(sqlString);
	 		return result;
	 	}
	 
	 public int productTypeDelete(int id) {
			// TODO Auto-generated method stub
			String sqlString = "delete from product_type where id = '"+id+"'";
			int result = DBManager.executeUpdate(sqlString);
			return result;
		}
}
